package com.glory.brepda.adapter;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.glory.brepda.entity.EquCallOutStateEntity;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;

import java.util.List;

public class GroupEquStateListCanCelAdapter extends BaseQuickAdapter<EquCallOutStateEntity.ResultBean, BaseViewHolder> {
    private boolean mStatus = true;
    private NetworkRequestCallback callback;

    private FragmentManager fragmentManager;
    public GroupEquStateListCanCelAdapter(@Nullable List<EquCallOutStateEntity.ResultBean> data, FragmentManager fragmentManager, NetworkRequestCallback callback) {
        super(R.layout.title_equipment_group,data);
        this.fragmentManager = fragmentManager;
        this.callback = callback;
    }

    @Override
    protected void convert(BaseViewHolder helper, EquCallOutStateEntity.ResultBean item) {
        helper.setText(R.id.tvLocation,item.getLocation());
        helper.setText(R.id.tvCarrierID,item.getAddress_Id());
        helper.setText(R.id.tvSource,item.getSource());
        helper.setText(R.id.tvEument_state,item.getEqumanet_state_name());

        if("CRE".equals(item.getState())){
            helper.setText(R.id.tvState,"未接工");
        }else{
            helper.setText(R.id.tvState,"已接工");        }

        helper.setText(R.id.tvOperation,"取消接工");

        if("QC".equals(item.getSource())){
            helper.setText(R.id.tvSource,"QC");
        }else if("TRANSFER".equals(item.getSource())){
            helper.setText(R.id.tvSource,"转工");
        }else{
            helper.setText(R.id.tvSource,"叫修");
        }

        helper.getView(R.id.tvOperation).setOnClickListener(view -> {

            FreeApi_DialogUtils.getConfirmAndCancelDialog(mContext, "是否确认取消接工?", new FreeUI_CommonCallback() {
                @Override
                public void onSuccess() {
                    if (callback != null) {
                        callback.requestPostNet(item.getOBJECTRRN(),item.getState()); // 调用回调方法
                    }
                }
            }, () -> {}).show(fragmentManager,"CONFIRM_DIALOG");

        });
    }

    public interface NetworkRequestCallback{
        void requestPostNet(long index,String type);
    }
}
